<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .top {
            font-weight: 700;
            text-align: center;
            line-height: 40px;
        }

        .list .item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: 20px;
        }

        .list .item img {
            vertical-align: bottom;
            width: 50px;
            border-radius: 50%;
        }
        .empty{
            text-align: center;
            color: red;
        }
    </style>
</head>

<body>
    <main id="app">
        <div class="top" >任务列表</div>
        <div class="list" v-if="tasklist.length !=0">
            <div class="item" v-for="(item,index) in tasklist" :key="index">
                <div class="left">
                    <img :src="item.pic" alt="">
                </div>
                <div class="content">
                    <div class="name">{{item.name}}</div>
                    <div class="desc">{{item.desc}}</div>
                </div>
                <div class="right">
                    <button @click="changeStatus(item)">{{item.status == 1 ?'去完成': (item.status == 2? '领取':'已领取')}}</button>
                    <!-- <button v-if="item.status ==1" @click="changeStatus(item)">去完成</button>
                    <button  v-else-if="item.status ==2" @click="changeStatus(item)">领取</button>
                    <button v-else @click="changeStatus(item)">已领取</button> -->
                </div>
            </div>
             <!-- <div class="empty" v-show="tasklist.length ==0">任务列表为空！</div> -->
             <!-- <div class="empty" v-if="tasklist.length ==0">任务列表为空！</div> -->
        </div>
             <div class="empty" v-else>任务列表为空！</div>

    </main>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    let v = new Vue({
        el: '#app', //el Vue实例挂载的dom节点
        data: {
            tasklist: [
                { id: 1, pic: './img/1.jpg', name: '咪咕视频流量', desc: '咪咕视频流量', status: 1 },
                { id: 2, pic: './img/1.jpg', name: '和彩云送福利', desc: '每月领取500M流量', status: 2 },
                { id: 3, pic: './img/1.jpg', name: '最高40元套餐折扣劵', desc: '每月领取500M流量', status: 3 },
                { id: 4, pic: './img/1.jpg', name: '吃喝玩乐季,超级秒杀', desc: '每月领取500M流量', status: 3 },
            ]
        },//data 定义响应式数据, data的类型可以是对象,也可以是函数
        //  data: function(){ return {} }, //使用函数的写法,可以在实例化对象时生成一个新的数据
        computed: {}, //computed 定义计算属性
        watch: {}, //watch 定义数据监听
        methods: {
            changeStatus(item){
                if(item.status ==1){
                    item.status = 2;
                }else if(item.status ==2){
                    item.status =3;
                }
            }
        }, //methods 定义方法(函数)
        filters: {}, //filters 定义过滤器
        directives: {}, //directives 定义自定义指令
        components: {}, //components 注册局部组件
    })
</script>